<template>
  <div>
    <el-table :data="list" border style="width: 100%">
      <!-- width="180" -->
      <el-table-column prop="aaa" label="设备编号" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="bbb" label="设备名称" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="ccc" label="设备地点" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="ddd" label="故障类型" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="eee" label="告警时间" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="fff" label="告警时长" show-overflow-tooltip> </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip>
        <template v-slot="{row}">
          <el-link type="primary">详情</el-link>
          <el-link type="danger" class="ml5" @click="onDel(row.id)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <div class="mt10">
      <el-button
        type="primary"
        icon="el-icon-plus"
        plain
        size="small"
        class="w-full"
        @click="showSelectDevice = true"
        >添加设备</el-button
      >
    </div>
    <select-device :visible.sync="showSelectDevice" @select="onAdd"></select-device>
  </div>
</template>

<script>
import SelectDevice from "./components/select-device.vue";
export default {
  name: "TsDeviceAdd",
  inject: ['conf'],
  computed: {
    list() {
      return this.conf.list
    }
  },
  components: {
    SelectDevice,
  },
  data() {
    return {
      showSelectDevice: false,
    };
  },
  created() {},
  mounted() {},
  methods: {
    onAdd(devices) {
      let data = devices.map(t=> ({id: t.id,aaa: `编号${t.id}`, bbb: t.aaa, ccc: t.bbb, ddd: t.fff, eee: t.ddd, fff: t.eee}))
      this.list.push(...data);
    },
    async onDel(id) {
      try {
        await this.$confirm('确认删除？', '提示', {type: 'warning'})
        let i= this.list.findIndex(t=> t.id === id)
        this.list.splice(i, 1)
      } catch (error) {
        
      }
    }
  },
  watch: {},
};
</script>

<style lang="scss" scoped></style>
